home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / GXARITH.H < prev    next >
Text File  |  1993-05-13  |  2KB  |  50 lines

  1. /* Copyright (C) 1990 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gxarith.h */
  20. /* Arithmetic macros for Ghostscript library */
  21.  
  22. /* Define an in-line abs function, good for any signed numeric type. */
  23. #define any_abs(x) ((x) < 0 ? -(x) : (x))
  24.  
  25. /* Test floating point values against zero. */
  26. #if arch_floats_are_IEEE && (arch_sizeof_float == arch_sizeof_int || arch_sizeof_float == arch_sizeof_long)
  27. #  if arch_sizeof_float == arch_sizeof_int
  28. #    define _f_as_int(f) *(int *)(&(f))
  29. #  else        /* arch_sizeof_float == arch_sizeof_long */
  30. #    define _f_as_int(f) *(long *)(&(f))
  31. #  endif
  32. #  define is_fzero(f) ((_f_as_int(f) << 1) == 0)    /* +0 or -0 */
  33. #  define is_fzero2(f1,f2) (((_f_as_int(f1) | _f_as_int(f2)) << 1) == 0)
  34. #  define is_fneg(f) ((_f_as_int(f)) < 0)    /* -0 is negative, oh well */
  35. #else        /* e.g. (i.e.?), VAX */
  36. #  define is_fzero(f) ((f) == 0.0)
  37. #  define is_fzero2(f1,f2) ((f1) == 0.0 && (f2) == 0.0)
  38. #  define is_fneg(f) ((f) < 0.0)
  39. #endif
  40.  
  41. /*
  42.  * Define a macro for computing log2(n), where n=1,2,4,...,128.
  43.  * Because some compilers limit the total size of a statement,
  44.  * this macro must only mention n once.  The macro should really
  45.  * only be used with compile-time constant arguments, but it will work
  46.  * even if n is an expression computed at run-time.
  47.  */
  48. #define small_exact_log2(n)\
  49.  ((uint)(05637042010L >> ((((n) % 11) - 1) * 3)) & 7)
  50.